import os
import platform
import subprocess

def create_new_interface(interface_name):
    try:
        command = f"sudo ip link add {interface_name} type dummy"
        os.system(command)
        command_up = f"sudo ip link set {interface_name} up"
        os.system(command_up)
        print(f"Network interface {interface_name} created and set up.")
    except Exception as e:
        print(f"Failed to create network interface {interface_name}. Error: {str(e)}")

def create_virtual_ip(ip_address, interface_name):
    system_platform = platform.system()

    if system_platform == "Linux":
        try:
            command = f"sudo ip addr add {ip_address}/24 dev {interface_name}"
            os.system(command)
            print(f"Virtual IP address {ip_address} added to interface {interface_name}.")
        except Exception as e:
            print(f"Failed to add virtual IP address {ip_address}. Error: {str(e)}")
    else:
        print("This script currently only supports Linux systems.")

if __name__ == "__main__":
    # IP addresses to add based on the qkd_key_manager_class example
    virtual_ips = ["192.168.1.1", "192.168.1.2"]
    for idx, virtual_ip in enumerate(virtual_ips, start=1):
        interface_name = f"dummy{idx}"
        create_new_interface(interface_name)
        create_virtual_ip(virtual_ip, interface_name)
